package tech.xujian.lock.distributed.lockdistributed.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.xujian.lock.distributed.lockdistributed.annotation.RedisLock;
import tech.xujian.lock.distributed.lockdistributed.annotation.RedisLockType;
import tech.xujian.lock.distributed.lockdistributed.service.RedisService;

@RestController
@RequestMapping("/lock")
public class LockController {


    @Autowired
    RedisService redisService;

    @RedisLock(type = RedisLockType.IP)
    @GetMapping("/test/ip")
    public String lockTest() throws InterruptedException {
        Thread.sleep(20000);
        return "succeed.";
    }

    @RedisLock(type = RedisLockType.COUNT)
    @GetMapping("/test/count")
    public String testCount() throws InterruptedException {
        Thread.sleep(20000);
        return "succeed.";
    }
}
